using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CSharpCustomControls
{
    [DefaultProperty("Category"), DefaultEvent("InvalidValue")] 
    [ToolboxData("<{0}:SixthSample runat=server></{0}:SixthSample>")]
    public class SixthSample : WebControl
    {
        protected override void CreateChildControls()
        {
            System.Web.UI.WebControls.TextBox txt;
            System.Web.UI.WebControls.Button btn;
            System.Web.UI.WebControls.Style stl;


            txt = new System.Web.UI.WebControls.TextBox();
            btn = new System.Web.UI.WebControls.Button();

            stl = this.ControlStyle;
            stl.BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset;

            txt.ID = "Text1";
            txt.ForeColor = System.Drawing.Color.Red;
            txt.MergeStyle(stl);
            this.Controls.Add(txt);

            btn.ID = "Button1";
            btn.ForeColor = System.Drawing.Color.Green;
            btn.MergeStyle(stl);
            this.Controls.Add(btn);

            System.Web.UI.WebControls.Style stl2;
            System.Web.UI.WebControls.TextBox txt3 = new System.Web.UI.WebControls.TextBox();

            stl2 = new System.Web.UI.WebControls.Style();
            stl2 = txt.ControlStyle;
            txt3.MergeStyle(stl);
            this.Controls.Add(txt3);

            System.Web.UI.WebControls.TextBox txt2;
            System.Web.UI.WebControls.Button btn2;
            System.Web.UI.WebControls.Style stl3;

            stl3 = this.ControlStyle;

            txt2 = new System.Web.UI.WebControls.TextBox();
            txt2.ID = "Text2";
            txt2.MergeStyle(stl3);
            this.Controls.Add(txt2);

            btn2 = new System.Web.UI.WebControls.Button();
            btn2.ID = "Button2";
            btn2.MergeStyle(stl3);
            this.Controls.Add(btn2);            
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            //comment this routine out to see the full results of the CreateChildControls method
            System.Web.UI.WebControls.Style stl;
            System.Web.UI.WebControls.TextBox txt;

            
            
            stl = new System.Web.UI.WebControls.Style();
            stl = this.ControlStyle;
            stl.ForeColor = System.Drawing.Color.Red;
            stl.AddAttributesToRender(writer);

            txt = new System.Web.UI.WebControls.TextBox();
            txt.Text = "hello, world";
            txt.RenderControl(writer);
        }

     }
}
